/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.command;

import com.zsmartsystems.zigbee.dongle.ember.ezsp.EzspFrameRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberCertificateData;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberPrivateKeyData;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberPublicKeyData;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember EZSP command <b>setPreinstalledCbkeData</b>.
 * <p>
 * Sets the device's CA public key, local certificate, and static private key on the NCP
 * associated with this node.
 * <p>
 * This class provides methods for processing EZSP commands.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EzspSetPreinstalledCbkeDataRequest extends EzspFrameRequest {
    public static final int FRAME_ID = 0xA2;

    /**
     * The Certificate Authority's public key.
     * <p>
     * EZSP type is <i>EmberPublicKeyData</i> - Java type is {@link EmberPublicKeyData}
     */
    private EmberPublicKeyData caCert;

    /**
     * The node's new certificate signed by the CA.
     * <p>
     * EZSP type is <i>EmberCertificateData</i> - Java type is {@link EmberCertificateData}
     */
    private EmberCertificateData myCert;

    /**
     * The node's new static private key.
     * <p>
     * EZSP type is <i>EmberPrivateKeyData</i> - Java type is {@link EmberPrivateKeyData}
     */
    private EmberPrivateKeyData myKey;

    /**
     * Serialiser used to serialise to binary line data
     */
    private EzspSerializer serializer;

    /**
     * Request constructor
     */
    public EzspSetPreinstalledCbkeDataRequest() {
        frameId = FRAME_ID;
        serializer = new EzspSerializer();
    }

    /**
     * The Certificate Authority's public key.
     * <p>
     * EZSP type is <i>EmberPublicKeyData</i> - Java type is {@link EmberPublicKeyData}
     *
     * @return the current caCert as {@link EmberPublicKeyData}
     */
    public EmberPublicKeyData getCaCert() {
        return caCert;
    }

    /**
     * The Certificate Authority's public key.
     *
     * @param caCert the caCert to set as {@link EmberPublicKeyData}
     */
    public void setCaCert(EmberPublicKeyData caCert) {
        this.caCert = caCert;
    }

    /**
     * The node's new certificate signed by the CA.
     * <p>
     * EZSP type is <i>EmberCertificateData</i> - Java type is {@link EmberCertificateData}
     *
     * @return the current myCert as {@link EmberCertificateData}
     */
    public EmberCertificateData getMyCert() {
        return myCert;
    }

    /**
     * The node's new certificate signed by the CA.
     *
     * @param myCert the myCert to set as {@link EmberCertificateData}
     */
    public void setMyCert(EmberCertificateData myCert) {
        this.myCert = myCert;
    }

    /**
     * The node's new static private key.
     * <p>
     * EZSP type is <i>EmberPrivateKeyData</i> - Java type is {@link EmberPrivateKeyData}
     *
     * @return the current myKey as {@link EmberPrivateKeyData}
     */
    public EmberPrivateKeyData getMyKey() {
        return myKey;
    }

    /**
     * The node's new static private key.
     *
     * @param myKey the myKey to set as {@link EmberPrivateKeyData}
     */
    public void setMyKey(EmberPrivateKeyData myKey) {
        this.myKey = myKey;
    }

    @Override
    public int[] serialize() {
        // Serialize the header
        serializeHeader(serializer);

        // Serialize the fields
        serializer.serializeEmberPublicKeyData(caCert);
        serializer.serializeEmberCertificateData(myCert);
        serializer.serializeEmberPrivateKeyData(myKey);
        return serializer.getPayload();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(137);
        builder.append("EzspSetPreinstalledCbkeDataRequest [networkId=");
        builder.append(networkId);
        builder.append(", caCert=");
        builder.append(caCert);
        builder.append(", myCert=");
        builder.append(myCert);
        builder.append(", myKey=");
        builder.append(myKey);
        builder.append(']');
        return builder.toString();
    }
}
